// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.QueryRuleset;

public sealed partial class QueryRule
{
	[JsonInclude, JsonPropertyName("actions")]
	public Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleActions Actions { get; set; }
	[JsonInclude, JsonPropertyName("criteria")]
	public ICollection<Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteria> Criteria { get; set; }
	[JsonInclude, JsonPropertyName("rule_id")]
	public Elastic.Clients.Elasticsearch.Id RuleId { get; set; }
	[JsonInclude, JsonPropertyName("type")]
	public Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleType Type { get; set; }
}

public sealed partial class QueryRuleDescriptor : SerializableDescriptor<QueryRuleDescriptor>
{
	internal QueryRuleDescriptor(Action<QueryRuleDescriptor> configure) => configure.Invoke(this);

	public QueryRuleDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleActions ActionsValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleActionsDescriptor ActionsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleActionsDescriptor> ActionsDescriptorAction { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteria> CriteriaValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteriaDescriptor CriteriaDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteriaDescriptor> CriteriaDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteriaDescriptor>[] CriteriaDescriptorActions { get; set; }
	private Elastic.Clients.Elasticsearch.Id RuleIdValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleType TypeValue { get; set; }

	public QueryRuleDescriptor Actions(Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleActions actions)
	{
		ActionsDescriptor = null;
		ActionsDescriptorAction = null;
		ActionsValue = actions;
		return Self;
	}

	public QueryRuleDescriptor Actions(Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleActionsDescriptor descriptor)
	{
		ActionsValue = null;
		ActionsDescriptorAction = null;
		ActionsDescriptor = descriptor;
		return Self;
	}

	public QueryRuleDescriptor Actions(Action<Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleActionsDescriptor> configure)
	{
		ActionsValue = null;
		ActionsDescriptor = null;
		ActionsDescriptorAction = configure;
		return Self;
	}

	public QueryRuleDescriptor Criteria(ICollection<Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteria> criteria)
	{
		CriteriaDescriptor = null;
		CriteriaDescriptorAction = null;
		CriteriaDescriptorActions = null;
		CriteriaValue = criteria;
		return Self;
	}

	public QueryRuleDescriptor Criteria(Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteriaDescriptor descriptor)
	{
		CriteriaValue = null;
		CriteriaDescriptorAction = null;
		CriteriaDescriptorActions = null;
		CriteriaDescriptor = descriptor;
		return Self;
	}

	public QueryRuleDescriptor Criteria(Action<Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteriaDescriptor> configure)
	{
		CriteriaValue = null;
		CriteriaDescriptor = null;
		CriteriaDescriptorActions = null;
		CriteriaDescriptorAction = configure;
		return Self;
	}

	public QueryRuleDescriptor Criteria(params Action<Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteriaDescriptor>[] configure)
	{
		CriteriaValue = null;
		CriteriaDescriptor = null;
		CriteriaDescriptorAction = null;
		CriteriaDescriptorActions = configure;
		return Self;
	}

	public QueryRuleDescriptor RuleId(Elastic.Clients.Elasticsearch.Id ruleId)
	{
		RuleIdValue = ruleId;
		return Self;
	}

	public QueryRuleDescriptor Type(Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleType type)
	{
		TypeValue = type;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ActionsDescriptor is not null)
		{
			writer.WritePropertyName("actions");
			JsonSerializer.Serialize(writer, ActionsDescriptor, options);
		}
		else if (ActionsDescriptorAction is not null)
		{
			writer.WritePropertyName("actions");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleActionsDescriptor(ActionsDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("actions");
			JsonSerializer.Serialize(writer, ActionsValue, options);
		}

		if (CriteriaDescriptor is not null)
		{
			writer.WritePropertyName("criteria");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, CriteriaDescriptor, options);
			writer.WriteEndArray();
		}
		else if (CriteriaDescriptorAction is not null)
		{
			writer.WritePropertyName("criteria");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteriaDescriptor(CriteriaDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (CriteriaDescriptorActions is not null)
		{
			writer.WritePropertyName("criteria");
			writer.WriteStartArray();
			foreach (var action in CriteriaDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryRuleset.QueryRuleCriteriaDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("criteria");
			JsonSerializer.Serialize(writer, CriteriaValue, options);
		}

		writer.WritePropertyName("rule_id");
		JsonSerializer.Serialize(writer, RuleIdValue, options);
		writer.WritePropertyName("type");
		JsonSerializer.Serialize(writer, TypeValue, options);
		writer.WriteEndObject();
	}
}